<?php

namespace App\Http\Requests;

use Illuminate\Validation\Rule;

class TagRequest extends Request
{
    public function rules()
    {

        //$this->route('id') 获取url占位符为id的数据
        switch ($this->method())
        {
            case  'POST' :
            {
                return [
                  'name' => 'required|unique:tags'
                ];
            }
            case 'PUT':
            case 'PATCH':
            {
              return [
                'name' => [
                  'required',
                  Rule::unique('tags')->ignore($this->route('id')),
                ],
                
              ];
            }
            case 'DELETE':
            case 'GET':
            default:
            {
                return [];
            }

        }
    }

    public function messages()
    {
       return [
           'name.required' => '标签名称不能为空',
           'id.required' => 'id不能为空',
           'name.unique' => '标签名称已存在,请重新填写'
       ];
    }
}
